from dotenv import load_dotenv
from langchain.prompts import PromptTemplate
from langchain_openai import ChatOpenAI
from langchain.output_parsers import DatetimeOutputParser


load_dotenv()
model = ChatOpenAI(model = "gpt-4o")
llm = ChatOpenAI(
   model="kimi-k2-0905-preview",
   api_key= "sk-kiwyK1Ylil1GkOEuHnjlAT2b5Sf1nXNxcEw51tUG6PW3aHlO",
    base_url="https://api.moonshot.cn/v1",
)
#定义模板格式
template = " "
#使用时间解析器
output_parser = DatetimeOutputParser()

prompt = PromptTemplate.from_template(
    template=template,
    partial_variables={"format_instructions": output_parser.get_format_instructions()},
)

#格式调用
chain = prompt | llm | output_parser
#执行（链路调用）
output = chain.invoke({"question":"新中国是什么时候成立的？"})
print(output)
#格式转换
format_string = "%Y年%m月%d日"
formatted_datetime = output.strftime(format_string)

print(formatted_datetime)



